/**
 * 
 */
package com.sunjq;

/**
 * @author SJQ
 *
 */
public class QuickSort {
	
	public void quickSort(int[] list, int start, int end) {
		
//		int start= 0; 
//		int end = list.length;
		int x = list[0];
		
		while (start < end) {
			while (start < end && list[end-1] > x) {
				end --;
			}
			if (list[end-1] < x) {
				list[start] = list[end-1];
			}
			
			while (start < end && list[start] < x){
				start++;
			}
			if (list[start] > x){
				list[end-1] = list[start];
			}
			
		}
		
		list[start] = x;


		for (int t = 0; t < list.length; t++) {
//			System.out.print("list[" +t + "] == >"+ list[t] + " ;");
			System.out.print(list[t] + ", ");
		}
		System.out.println("quick sort");
//		for (end = list.length -1; end > start; end --) {
//			if (list[end] < x) {
//				temp = list[end];
//				list[end] = x;
//			}
//		}
		
		quickSort(list, 0, start);
		quickSort(list, start + 1, list.length);
	}
	
	public static void main (String[] args) {
		int[] list = {72,23,56,17,134,36};
		System.out.println("Original start");
		for (int t = 0; t < list.length; t++) {
		
			System.out.print(list[t] + ", ");
		
		}
		System.out.println();
		System.out.println("Original end");
		QuickSort qs = new QuickSort();
		qs.quickSort(list, 0, list.length);
	}

}
